/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sanger;

import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.PutObjectRequest;
import java.io.File;
import java.io.IOException;

/**
 *
 * @author lorddoskias
 */
public class AWSUpload {
    
    
    public static void uploadToAws(File f) throws IOException {

        AmazonS3 s3 = Constants.getS3Obj();

        //System.out.println("Uploading a new object to S3 from a file\n");
        try {
            s3.putObject(new PutObjectRequest(Constants.BUCKET, Constants.AWS_DIR + f.getName(), f));
        } catch (AmazonServiceException ase) {
            System.out.println("Caught an AmazonServiceException, which means your request made it "
                    + "to Amazon S3, but was rejected with an error response for some reason.");
            System.out.println("Error Message:    " + ase.getMessage());
            System.out.println("HTTP Status Code: " + ase.getStatusCode());
            System.out.println("AWS Error Code:   " + ase.getErrorCode());
            System.out.println("Error Type:       " + ase.getErrorType());
            System.out.println("Request ID:       " + ase.getRequestId());
        } catch (AmazonClientException ace) {
            System.out.println("Caught an AmazonClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with S3, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message: " + ace.getMessage());
        }
    }
}
